/**
 * @author LKQ
 * @date 2021/12/7 14:47
 * @description 深度优先搜索，二叉树的最大深度为max(l,r)+1。
 */
public class Solution {
    public static void main(String[] args) {
        TreeNode leaf9 = new TreeNode(9, null, null);
        TreeNode leaf15 = new TreeNode(15, null, null);
        TreeNode leaf7 = new TreeNode(7, null, null);
        TreeNode leaf20 = new TreeNode(20, leaf15, leaf7);
        TreeNode root = new TreeNode(3, leaf9, leaf20);
        Solution solution = new Solution();
        System.out.println(solution.maxDepth(root));
    }

    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        return Math.max(maxDepth(root.left) + 1, maxDepth(root.right) + 1);
    }
}
